//
//  FKSearchHistoryHeader.m
//  HappyTest
//
//  Created by Macbook Pro on 2019/1/21.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKSearchHistoryHeader.h"

@interface FKSearchHistoryHeader ()

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UIButton *deleteBtn;

@end

@implementation FKSearchHistoryHeader

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        UILabel *titleLabel = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkColor333333];
        [self addSubview:titleLabel];
        self.titleLabel = titleLabel;
        
        UIButton *deleteBtn = [UIButton fk_btnWithTarget:self action:@selector(deleteBtnClicked) img:[UIImage imageNamed:@"search_delete"]];
        [self addSubview:deleteBtn];
        self.deleteBtn = deleteBtn;
        deleteBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        deleteBtn.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
        
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(0); // 因为collectionView本身加了inset
            make.centerY.offset(0);
        }];
        [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.offset(0);  // 因为collectionView本身加了inset
            make.top.equalTo(titleLabel);
            make.width.height.mas_equalTo(fk_adjustW(44));
        }];
    }
    return self;
}

- (void)deleteBtnClicked
{
    if (self.deleteBlock) {
        self.deleteBlock();
    }
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    
    self.titleLabel.text = title;
}

- (void)setShowDelete:(BOOL)showDelete
{
    _showDelete = showDelete;
    
    self.deleteBtn.hidden = !showDelete;
}

@end
